FROM golang:1.19.4 as BUILDER
LABEL maintainer="zhangjianjun"
RUN go env -w GOPROXY=https://goproxy.cn,direct

# build binary
RUN mkdir -p /go/src/gitee.com/openeuler/cve-manager
COPY . /go/src/gitee.com/openeuler/cve-manager
RUN cd /go/src/gitee.com/openeuler/cve-manager && CGO_ENABLED=1 go build -v -o ./cve-manager main.go

# copy binary config and utils
FROM openeuler/openeuler:22.03
RUN dnf -y update && \
    dnf in -y shadow && \
    groupadd -g 1000 manager && \
    useradd -u 1000 -g manager -s /bin/bash -m manager

COPY --chown=manager ./conf/product_app.conf /opt/app/conf/app.conf
COPY --chown=manager ./sh/epoch.sh /opt/app/epoch.sh
COPY --chown=manager --from=BUILDER /go/src/gitee.com/openeuler/cve-manager/cve-manager /opt/app/cve-manager

USER manager
WORKDIR /opt/app
RUN mkdir logs

ENTRYPOINT ["/opt/app/cve-manager"]